package edu.hm.activebadge.rfid.representation;

import java.io.IOException;
import java.util.Calendar;
import java.util.GregorianCalendar;

import org.jdom.JDOMException;

import edu.hm.activebadge.rfid.storage.XMLStorage;

public class ContextMarkup implements IContextRepresentation {
	
	private String badge;
	private String tag;
	private boolean add;

	private GregorianCalendar timestamp;
	
	private XMLStorage storage;

	public ContextMarkup(){
		try {
			storage = new XMLStorage();
		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public String getBadge() {
		return badge;
	}


	public void setBadge(String badge) {
		this.badge = badge;
	}


	public String getTag() {
		return tag;
	}


	public void setTag(String tag) {
		this.tag = tag;
	}


	public void setAdd(boolean a) {
		this.add = a;
	}


	public GregorianCalendar getTimestamp() {
		return timestamp;
	}


	public void setTimestamp(GregorianCalendar timestamp) {
		this.timestamp = timestamp;
	}


	public String identifyYourself() {
		
		return("Die UID "+tag+" wurde am "+timestamp.get(Calendar.DAY_OF_MONTH)+"."+timestamp.get(Calendar.MONTH)+"."+timestamp.get(Calendar.YEAR)+" um "+timestamp.get(Calendar.HOUR_OF_DAY)+":"+timestamp.get(Calendar.MINUTE)+":"+timestamp.get(Calendar.SECOND)+" durch den Badge "+badge+" erkannt");
	}
	
	public boolean isSameTag(IContextRepresentation toCompare){
		
		if(toCompare!=null)
			return(badge.equals(toCompare.getBadge())&&tag.equals(toCompare.getTag()));
		else
			return false;
	}

	public void capture(String b, String t, boolean a, GregorianCalendar ts) {
		badge = b;
		tag = t;
		add = a;
		timestamp = ts;

	}

	public void process() {
		storage.saveContextChange(this);
		try {
			storage.writeDoc();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	public boolean getAdd() {
		return add;
	}

}
